"use strict";
/// <reference types="../../../node_modules/.vue-global-types/vue_3.5_false.d.ts" />
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
    if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
        if (ar || !(i in from)) {
            if (!ar) ar = Array.prototype.slice.call(from, 0, i);
            ar[i] = from[i];
        }
    }
    return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
var vue_1 = require("vue");
var usePreview_ts_1 = require("./hook/usePreview.ts");
var props = defineProps({
    isPreviewOpen: {
        type: Boolean,
        required: true,
        default: false
    },
    filePreviewLink: {
        type: String,
        required: true,
        default: ''
    },
    fileName: {
        type: String,
        required: true,
        default: ''
    },
    keyTimer: {
        type: Number,
        required: true,
        default: 0
    },
});
var visible = (0, vue_1.ref)(false);
var componentName = (0, vue_1.ref)();
// 关闭弹窗的方法
var close = function () {
    visible.value = false;
};
// 监听键盘的esc事件
var handleKeydown = function (event) {
    if (event.key === 'Escape') {
        close();
    }
};
// 通过链接下载文件
var download = function () {
    var a = document.createElement('a');
    a.href = props.filePreviewLink;
    a.download = props.fileName;
    a.click();
};
// 在组件挂载时监听esc事件
(0, vue_1.onMounted)(function () {
    window.addEventListener('keydown', handleKeydown);
});
// 在组件销毁前移除esc事件监听
(0, vue_1.onBeforeUnmount)(function () {
    window.removeEventListener('keydown', handleKeydown);
});
(0, vue_1.watch)(function () { return props.keyTimer; }, function (newVal) {
    visible.value = true;
    console.log(props.filePreviewLink);
    if (props.fileName.indexOf('.') !== -1) {
        var _a = (0, usePreview_ts_1.useFilePreview)({ url: props.filePreviewLink, name: props.fileName }).previewInfo, url = _a.url, name_1 = _a.name, component = _a.component;
        // 动态导入组件
        componentName.value = component;
        console.log(componentName.value);
    }
}, { immediate: true, deep: true }); /* PartiallyEnd: #3632/scriptSetup.vue */
function __VLS_template() {
    var __VLS_ctx = {};
    var __VLS_components;
    var __VLS_directives;
    ['modal-body',];
    // CSS variable injection 
    // CSS variable injection end 
    if (__VLS_ctx.visible) {
        __VLS_elementAsFunction(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)(__assign({ onClick: (__VLS_ctx.close) }, { class: ("modal-overlay") }));
        __VLS_elementAsFunction(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)(__assign({ class: ("modal-content") }));
        __VLS_elementAsFunction(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)(__assign({ class: ("modal-options") }));
        __VLS_elementAsFunction(__VLS_intrinsicElements.p, __VLS_intrinsicElements.p)({});
        (__VLS_ctx.fileName);
        __VLS_elementAsFunction(__VLS_intrinsicElements.p, __VLS_intrinsicElements.p)({});
        __VLS_elementAsFunction(__VLS_intrinsicElements.button, __VLS_intrinsicElements.button)(__assign({ onClick: (__VLS_ctx.download) }));
        __VLS_elementAsFunction(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)(__assign({ class: ("modal-body") }));
        var __VLS_0 = ((__VLS_ctx.componentName));
        // @ts-ignore
        var __VLS_1 = __VLS_asFunctionalComponent(__VLS_0, new __VLS_0({
            filePath: ((__VLS_ctx.filePreviewLink)),
        }));
        var __VLS_2 = __VLS_1.apply(void 0, __spreadArray([{
                filePath: ((__VLS_ctx.filePreviewLink)),
            }], __VLS_functionalComponentArgsRest(__VLS_1), false));
    }
    ['modal-overlay', 'modal-content', 'modal-options', 'modal-body',];
    var __VLS_slots;
    var $slots;
    var __VLS_inheritedAttrs;
    var $attrs;
    var __VLS_refs = {};
    var $refs;
    var $el;
    return {
        attrs: {},
        slots: __VLS_slots,
        refs: $refs,
        rootEl: $el,
    };
}
;
var __VLS_self = (await Promise.resolve().then(function () { return require('vue'); })).defineComponent({
    setup: function () {
        return {
            visible: visible,
            componentName: componentName,
            close: close,
            download: download,
        };
    },
    props: {
        isPreviewOpen: {
            type: Boolean,
            required: true,
            default: false
        },
        filePreviewLink: {
            type: String,
            required: true,
            default: ''
        },
        fileName: {
            type: String,
            required: true,
            default: ''
        },
        keyTimer: {
            type: Number,
            required: true,
            default: 0
        },
    },
});
exports.default = (await Promise.resolve().then(function () { return require('vue'); })).defineComponent({
    setup: function () {
        return {};
    },
    props: {
        isPreviewOpen: {
            type: Boolean,
            required: true,
            default: false
        },
        filePreviewLink: {
            type: String,
            required: true,
            default: ''
        },
        fileName: {
            type: String,
            required: true,
            default: ''
        },
        keyTimer: {
            type: Number,
            required: true,
            default: 0
        },
    },
});
; /* PartiallyEnd: #4569/main.vue */
